package cn.cvs.mapper;

import cn.cvs.pojo.SysRight;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface SysRightMapper extends BaseMapper<SysRight> {

    /*@Select("SELECT sr.right_url,sr.right_type,sr.right_text,sr.right_code" +
            " FROM sys_role_right rr" +
            " inner join sys_right sr" +
            " on rr.rf_right_code =sr.right_code")
    @Results(value = {
            @Result(property = "rightCode",column = "right_code")
            ,@Result(property = "rightUrl",column = "right_url")
            ,@Result(property = "rightType",column = "right_type")
            ,@Result(property = "rightText",column = "right_text")
    })*/
    @Select("SELECT sr.right_url,sr.right_type,sr.right_text,sr.right_code,sr.right_parent_code" +
            " FROM sys_right sr")
    @Results(value = {
            @Result(property = "rightCode",column = "right_code")
            ,@Result(property = "rightUrl",column = "right_url")
            ,@Result(property = "rightType",column = "right_type")
            ,@Result(property = "rightText",column = "right_text")
            ,@Result(property = "rightParentCode",column = "right_parent_code")
    })
    public List<SysRight> getAllSysRight();//shiro过滤器链查所有权限

    @Select("SELECT sr.right_url,sr.right_type,sr.right_text,sr.right_code,sr.right_parent_code" +
            " FROM  sys_role r" +
            " left join sys_role_right rr" +
            " on r.role_id =rr.rf_role_id" +
            " inner join sys_right sr" +
            " on rr.rf_right_code =sr.right_code" +
            " where r.role_id=#{roleId}")
    //登录时按roleId查权限,授权时从主体获得并遍历加入zinfo
    public List<SysRight> getSysRightByUserRoleId(Long roleId);
}
